package pATT.profilingAlgorithm.PersonalSearcher;


import java.io.Serializable;



public class Instance implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String			instance_id;
	private TermVector		instance_words;
	private String			instance_file;
	private String			instance_class;
	private double			relevance;
	private long			date;
	private String			feedback;
	private String			title;
	private String			url;//TODO agregado PATT

	public Instance(String id, TermVector w, String u, String clas){
		instance_id=id;
		instance_words=w;
		instance_file=u;
		instance_class=clas;
		relevance = 0;
	}

	public TermVector getVector(){
		return instance_words;
	}

	public void setDate(long d){
		date = d;
	}

	public String getFile(){
		return instance_file;
	}

	public String getTitle(){
		return title;
	}

	public void setTitle(String t){
		title = t;
	}

	public String getClassification(){
		return instance_class;
	}

	public String getID(){
		return instance_id;
	}

	public void setFeedback(double v){
		relevance = sigmoid(v);
	}

	public void addFeedback(double f, double conf){
		relevance = sigmoid(inverseSigmoid(relevance)+(f*conf));
	}

	public void setTxtFeedback(String s){
  		feedback = s;
	}

	public String getTxtFeedback(){
  		return feedback;
	}

	public double getRelevance(){
  		return relevance;
	}

	public double sigmoid(double x){
		return (2 / (1+Math.exp(-2*x)))-1;
	}
	
	public double inverseSigmoid(double v){
		return	Math.log(((2 / (v+1))-1)) / -2;
	}
	
	public void setVector(TermVector v){
  	instance_words=v;
	}

	public void setFile(String f){
  	instance_file=f;
	}

	public void setClassification(String c){
		instance_class=c;
	}

	public Instance subtract(TermVector v){
		instance_words.subtract(v);
  		return this;
	}

	public void setID(String id){
  	instance_id=id;
	}

	public int size(){
  	return instance_words.size();
	}

	public String toString(){
		return instance_id+"|"+instance_class+"|"+instance_file+"|"+instance_words;
	}


	public void normalizeAugmented(){
		instance_words.normalizeAugmented();
	}
	
		public void normalizeSquare(){
		instance_words.normalizeSquare();
	}

	public double compareIntersection(TermVector t){
		return instance_words.compareIntersection(t);
	}


	public double compare(Instance newinstance){
		return this.compare(newinstance,new TermVector());
	}

	public double compare(Instance newinstance,TermVector toRemove){
		return instance_words.cosine(newinstance.getVector(),toRemove);
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public long getDate() {
		return date;
	}
	
	
	
	
}
